package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mappers.SoulOptionsMapper;
import com.tanhua.model.testpaper.SoulOptions;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
@Slf4j
@DubboService
public class SoulOptionsApiImpl implements SoulOptionsApi{
    @Autowired
    private SoulOptionsMapper soulOptionsMapper;
    @Override
    public List<SoulOptions> findByQuestionsIds(List<Long> soulQuestionsIds) {
        List<SoulOptions> soulOptions =new ArrayList<>();
        for (Long soulQuestionsId : soulQuestionsIds) {
            LambdaQueryWrapper<SoulOptions> lqw=new LambdaQueryWrapper<>();
            lqw.eq(SoulOptions::getQuestionsId,soulQuestionsId);
            List<SoulOptions> soulOptions1 = soulOptionsMapper.selectList(lqw);
            for (SoulOptions options : soulOptions1) {
                soulOptions.add(options);
            }
        }
        return soulOptions;
    }

    @Override
    public List<SoulOptions> findAll() {
        List<SoulOptions> soulOptions = soulOptionsMapper.selectList(new LambdaQueryWrapper<>());

        return soulOptions;
    }
//获取分数
    @Override
    public Double findScore(Long questionId, Long optionId) {
      LambdaQueryWrapper<SoulOptions>lqw=new LambdaQueryWrapper<>();
      lqw.eq(SoulOptions::getId,optionId);
      lqw.eq(SoulOptions::getQuestionsId,questionId);
      lqw.select(SoulOptions::getScore);
        SoulOptions soulOptions = soulOptionsMapper.selectOne(lqw);

        return soulOptions.getScore();
    }
}
